package com.iplant.wms.serviceImpl;

import com.iplant.base.po.OutResult;
import com.iplant.base.po.Pagination;
import com.iplant.base.po.ServiceResult;
import com.iplant.base.po.enums.ExceptionTypes;
import com.iplant.base.po.excel.ExcelData;
import com.iplant.base.po.excel.ExcelLineData;
import com.iplant.base.po.excel.ExcelSheetData;
import com.iplant.base.utils.general.CalendarTool;
import com.iplant.base.utils.general.StringUtils;
import com.iplant.base.utils.sql.orm.ORMUtils;
import com.iplant.base.utils.sql.orm.PoService;
import com.iplant.basic.service.po.bms.BMSEmployee;
import com.iplant.basic.service.po.mss.MSSMaterial;
import com.iplant.basic.service.po.mss.MSSUnit;
import com.iplant.basic.serviceImpl.dao.mss.MSSMaterialDAO;
import com.iplant.wms.service.ASNService;
import com.iplant.wms.service.basicenum.asn.WMSReceiveStatus;
import com.iplant.wms.service.basicenum.brm.BRMShelvesTypes;
import com.iplant.wms.service.basicenum.wms.WMSPickingMode;
import com.iplant.wms.service.po.asn.*;
import com.iplant.wms.service.po.asn.imp.WMSArrivalNoticeItemImpo;
import com.iplant.wms.service.po.brm.BRMShelvesProp;
import com.iplant.wms.service.po.brm.BRMShelvesRange;
import com.iplant.wms.service.po.mfs.WMSStoreStation;
import com.iplant.wms.service.po.mss.MSSMaterialStation;
import com.iplant.wms.service.po.pkg.MSSPackageProp;
import com.iplant.wms.service.po.wms.WMSStock;
import com.iplant.wms.service.po.wpo.WMSPurchaseOrder;
import com.iplant.wms.serviceImpl.dao.asn.*;
import com.iplant.wms.serviceImpl.dao.asn.WMSReceiveBillDAO;
import com.iplant.wms.serviceImpl.dao.asn.WMSReceiveBillItemDAO;
import com.iplant.wms.serviceImpl.dao.bill.WMSOutboundOrderDAO;
import com.iplant.wms.serviceImpl.dao.brm.BRMShelvesPropDAO;
import com.iplant.wms.serviceImpl.dao.brm.BRMShelvesRangeDAO;
import com.iplant.wms.serviceImpl.dao.mfs.WMSStoreStationDAO;
import com.iplant.wms.serviceImpl.dao.mrp.MRPDeliveryDAO;
import com.iplant.wms.serviceImpl.dao.mss.MSSMaterialStationDAO;
import com.iplant.wms.serviceImpl.dao.pkg.MSSPackagePropDAO;
import com.iplant.wms.serviceImpl.dao.wms.WMSStockRecordDAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

@Service
public class ASNServiceImpl implements ASNService {

    private static Logger logger = LoggerFactory.getLogger(ASNServiceImpl.class);

    public ASNServiceImpl() {
    }

    private static ASNService Instance;

    public static ASNService getInstance() {
        if (Instance == null) {
            Instance = new ASNServiceImpl();
        }
        return Instance;
    }

    //region POService
    PoService<MSSMaterial> mMSSMaterialService = ORMUtils.GetPoService(MSSMaterial.class);
    PoService<MSSUnit> mMSSUnitService = ORMUtils.GetPoService(MSSUnit.class);
    //endregion

    @Override
    public ServiceResult<Integer> WMS_UpdateArrivalNotice(BMSEmployee wLoginUser, WMSArrivalNotice wArrivalNotice) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);


            wResult.Result = WMSArrivalNoticeDAO.getInstance().UpdatePo(
                    wLoginUser, wArrivalNotice, wErrorCode);

            wResult.AddFaultCode(wErrorCode);
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<Integer> WMS_DeleteArrivalNoticeList(
            BMSEmployee wLoginUser, List<WMSArrivalNotice> wArrivalNoticeList) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);


            WMSArrivalNoticeDAO.getInstance().WMS_DeleteArrivalNoticeList(wLoginUser, wArrivalNoticeList, wErrorCode);

            wResult.AddFaultCode(wErrorCode);
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<Integer> WMS_DeleteArrivalNotice(
            BMSEmployee wLoginUser, WMSArrivalNotice wArrivalNotice) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);


            WMSArrivalNoticeDAO.getInstance().WMS_DeleteArrivalNotice(wLoginUser, wArrivalNotice, wErrorCode);

            wResult.AddFaultCode(wErrorCode);
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<Integer> WMS_ImportArrivalNotice(BMSEmployee wLoginUser, ExcelData wExcelData) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            // ①采购订单
            List<WMSArrivalNotice> wWMSArrivalNoticeList = WMSArrivalNoticeDAO.getInstance().GetWMSArrivalNoticeList(
                    wLoginUser, wExcelData, wErrorCode);
            if (wErrorCode.Result != 0) {
                wResult.AddFaultCode(wErrorCode);
                return wResult;
            }
            Map<String, Integer> wOrderNoMap = new HashMap<>();

            WMSArrivalNoticeDAO.getInstance().UpdatePoList(wLoginUser, wWMSArrivalNoticeList, wErrorCode);

            if (wErrorCode.Result != 0) {
                wResult.AddFaultCode(wErrorCode);
                return wResult;
            }

            List<Integer> wIDList =
                    wWMSArrivalNoticeList.stream().filter(p -> p.ID > 0).map(p -> p.ID).distinct().collect(Collectors.toList());

            WMSArrivalNoticeItemDAO.getInstance().WMS_DeleteArrivalNoticeItem(
                    wLoginUser, wIDList, wErrorCode);

            if (wErrorCode.Result != 0) {
                wResult.AddFaultCode(wErrorCode);
                return wResult;
            }
            // ②采购订单明细
            List<WMSArrivalNoticeItem> wWMSArrivalNoticeItemList =
                    WMSArrivalNoticeItemDAO.getInstance().WMS_GetArrivalNoticeItemList(wLoginUser, wExcelData,
                            wErrorCode);
            if (wErrorCode.Result != 0) {
                wResult.AddFaultCode(wErrorCode);
                return wResult;
            }
            WMSArrivalNoticeItemDAO.getInstance().UpdatePoList(
                    wLoginUser, wWMSArrivalNoticeItemList, wErrorCode);

            wResult.AddFaultCode(wErrorCode);
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<WMSArrivalNotice> WMS_CreateArrivalNotice(BMSEmployee wLoginUser,
                                                                   WMSPurchaseOrder wWMSPurchaseOrder) {
        ServiceResult<WMSArrivalNotice> wResult = new ServiceResult<WMSArrivalNotice>();
        wResult.Result = new WMSArrivalNotice();
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);
            wResult.Result = WMSArrivalNoticeDAO.getInstance().WMS_CreateFromPurchaseOrder(wLoginUser,
                    wWMSPurchaseOrder, wErrorCode);
            wResult.AddFaultCode(wErrorCode);
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<WMSArrivalNotice> WMS_QueryArrivalNotice(BMSEmployee wLoginUser, int wID, String wCode) {
        ServiceResult<WMSArrivalNotice> wResult = new ServiceResult<WMSArrivalNotice>();
        wResult.Result = new WMSArrivalNotice();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            wResult.Result = WMSArrivalNoticeDAO.getInstance().SelectPO(
                    wLoginUser, wID, wCode, wErrorCode);

            wResult.AddFaultCode(wErrorCode);
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<Integer> WMS_UpdateArrivalNoticeItemList(
            BMSEmployee wLoginUser, List<WMSArrivalNoticeItem> wWMSArrivalNoticeItemList) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);


            for (WMSArrivalNoticeItem wWMSArrivalNoticeItem : wWMSArrivalNoticeItemList) {
                wWMSArrivalNoticeItem.setUserInfo(wLoginUser);
                WMSArrivalNoticeItemDAO.getInstance().WMS_UpdateArrivalNoticeItem(
                        wLoginUser, wWMSArrivalNoticeItem, wErrorCode);
                if (wErrorCode.Result != 0) {
                    wWMSArrivalNoticeItem.Description = ExceptionTypes.getEnumType(wErrorCode.Result).getLabel();
                    wResult.FaultCode += StringUtils.Format("\n Code:{0}  Error:{1}", wWMSArrivalNoticeItem.Code,
                            wWMSArrivalNoticeItem.Description);
                }
            }
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<Integer> WMS_UpdateArrivalNoticeItem(BMSEmployee wLoginUser, WMSArrivalNoticeItem wItem) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);

        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            wResult.Result = WMSArrivalNoticeItemDAO.getInstance().WMS_UpdateArrivalNoticeItem(wLoginUser, wItem,
                    wErrorCode);

            wResult.AddFaultCode(wErrorCode);
        } catch (Exception ex) {
            wResult.FaultCode += ex.toString();
            logger.error(ex.toString());
        }

        return wResult;
    }

    @Override
    public ServiceResult<Integer> WMS_DeleteArrivalNoticeItemList(
            BMSEmployee wLoginUser, List<WMSArrivalNoticeItem> wArrivalNoticeItemList) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);


            WMSArrivalNoticeItemDAO.getInstance().WMS_DeleteArrivalNoticeItemList(
                    wLoginUser, wArrivalNoticeItemList, wErrorCode);

            wResult.AddFaultCode(wErrorCode);
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> WMS_DeleteArrivalNoticeItem(
            BMSEmployee wLoginUser, WMSArrivalNoticeItem wWMSArrivalNoticeItem) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);


            WMSArrivalNoticeItemDAO.getInstance().WMS_DeleteArrivalNoticeItem(
                    wLoginUser, wWMSArrivalNoticeItem, wErrorCode);

            wResult.AddFaultCode(wErrorCode);
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<WMSArrivalNoticeItem> WMS_QueryArrivalNoticeItem(
            BMSEmployee wLoginUser, int wID, String wCode) {
        ServiceResult<WMSArrivalNoticeItem> wResult = new ServiceResult<>();
        wResult.Result = new WMSArrivalNoticeItem();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            wResult.Result = WMSArrivalNoticeItemDAO.getInstance().SelectPO(
                    wLoginUser, wID, wCode, wErrorCode);

            wResult.AddFaultCode(wErrorCode);
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<Integer> WMS_UpdateArrivalVehicleList(
            BMSEmployee wLoginUser, List<WMSArrivalVehicle> wWMSArrivalVehicleList) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            WMSArrivalVehicleDAO.getInstance().UpdatePoList(wLoginUser, wWMSArrivalVehicleList, wErrorCode);

            wResult.AddFaultCode(wErrorCode);
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<Integer> WMS_DeleteArrivalVehicleList(
            BMSEmployee wLoginUser, List<WMSArrivalVehicle> wArrivalVehicleList) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);


            WMSArrivalVehicleDAO.getInstance().DeletePOList(
                    wLoginUser, wArrivalVehicleList, wErrorCode);

            wResult.AddFaultCode(wErrorCode);
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }


    //region 收货单主单据

    /**
     * 由到货单及其子项，创建收货单及其子项
     *
     * @param wLoginUser
     * @param wWMSArrivalNotice
     * @return
     */
    @Override
    public ServiceResult<WMSReceiveBill> WMS_CreateReceiveBill(BMSEmployee wLoginUser,
                                                               WMSArrivalNotice wWMSArrivalNotice) {
        ServiceResult<WMSReceiveBill> wResult = new ServiceResult<>();

        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            wResult.Result = WMSReceiveBillDAO.getInstance().WMS_CreateFromArrival(wLoginUser, wWMSArrivalNotice,
                    wErrorCode);
            wResult.AddFaultCode(wErrorCode);
        } catch (Exception ex) {
            wResult.FaultCode += ex.toString();
            logger.error(ex.toString());
        }

        return wResult;
    }

    /**
     * 添加或修改收货单
     *
     * @param wLoginUser
     * @param wItem
     * @return
     */
    @Override
    public ServiceResult<Integer> WMS_UpdateReceiveBill(BMSEmployee wLoginUser, WMSReceiveBill wItem) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);

        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            wResult.Result = WMSReceiveBillDAO.getInstance().UpdatePo(wLoginUser, wItem, wErrorCode);


            if (wErrorCode.Result != 0) {
                wResult.AddFaultCode(wErrorCode);
                return wResult;
            }

            MRPDeliveryDAO.getInstance().MRP_UpdateDeliveryFQTYDone(wLoginUser,
                    wItem.CreateTime, Calendar.getInstance(), wErrorCode);

            wResult.AddFaultCode(wErrorCode);
        } catch (Exception ex) {
            wResult.FaultCode += ex.toString();
            logger.error(ex.toString());
        }

        return wResult;
    }

    /**
     * 删除单条收货单及其子项
     *
     * @param wLoginUser
     * @param wItem
     * @return
     */
    @Override
    public ServiceResult<Integer> WMS_DeleteReceiveBill(BMSEmployee wLoginUser, WMSReceiveBill wItem) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);

        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            WMSReceiveBillDAO.getInstance().DeletePO(wLoginUser, wItem, wErrorCode);

            if (wErrorCode.Result != 0) {
                wResult.AddFaultCode(wErrorCode);
                return wResult;
            }

            MRPDeliveryDAO.getInstance().MRP_UpdateDeliveryFQTYDone(wLoginUser,
                    wItem.CreateTime, Calendar.getInstance(), wErrorCode);
        } catch (Exception ex) {
            wResult.FaultCode += ex.toString();
            logger.error(ex.toString());
        }

        return wResult;
    }

    /**
     * 批量删除收货单及其子项（传对象集合）
     *
     * @param wLoginUser
     * @param wItemList
     * @return
     */
    @Override
    public ServiceResult<Integer> WMS_DeleteReceiveBillList(BMSEmployee wLoginUser, List<WMSReceiveBill> wItemList) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);

        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            WMSReceiveBillDAO.getInstance().DeletePOList(wLoginUser, wItemList, wErrorCode);
            if (wErrorCode.Result != 0) {
                wResult.AddFaultCode(wErrorCode);
                return wResult;
            }
            Calendar createTime = wItemList.stream().min(Comparator.comparingInt(o -> o.ID)).get().CreateTime;

            MRPDeliveryDAO.getInstance().MRP_UpdateDeliveryFQTYDone(wLoginUser,
                    createTime, Calendar.getInstance(), wErrorCode);

            wResult.AddFaultCode(wErrorCode);
        } catch (Exception ex) {
            wResult.FaultCode += ex.toString();
            logger.error(ex.toString());
        }

        return wResult;
    }


    @Override
    public ServiceResult<Integer> WMS_DeleteReceiveBillListByIDList(BMSEmployee wLoginUser, List<Integer> wIDList) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);

        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            List<WMSReceiveBill> wItemList = WMSReceiveBillDAO.getInstance().SelectPOList(wLoginUser, wIDList,
                    Pagination.getNewMaxSize(), wErrorCode);

            if (wErrorCode.Result != 0) {
                wResult.AddFaultCode(wErrorCode);
                return wResult;
            }

            WMSReceiveBillDAO.getInstance().DeletePOList(wLoginUser, wItemList, wErrorCode);
            if (wErrorCode.Result != 0) {
                wResult.AddFaultCode(wErrorCode);
                return wResult;
            }
            Calendar createTime = wItemList.stream().min(Comparator.comparingInt(o -> o.ID)).get().CreateTime;

            MRPDeliveryDAO.getInstance().MRP_UpdateDeliveryFQTYDone(wLoginUser,
                    createTime, Calendar.getInstance(), wErrorCode);

            wResult.AddFaultCode(wErrorCode);

        } catch (Exception ex) {
            wResult.FaultCode += ex.toString();
            logger.error(ex.toString());
        }

        return wResult;
    }

    /**
     * 根据ID或Code查询单条收货单
     *
     * @param wLoginUser
     * @param wID
     * @param wCode
     * @return
     */
    @Override
    public ServiceResult<WMSReceiveBill> WMS_QueryReceiveBillByIDOrCode(BMSEmployee wLoginUser, Integer wID,
                                                                        String wCode) {
        ServiceResult<WMSReceiveBill> wResult = new ServiceResult<>();

        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            wResult.Result = WMSReceiveBillDAO.getInstance().SelectPO(wLoginUser, wID, wCode, wErrorCode);
            wResult.AddFaultCode(wErrorCode);
        } catch (Exception ex) {
            wResult.FaultCode += ex.toString();
            logger.error(ex.toString());
        }

        return wResult;
    }


    /**
     * 查询指定时间段内的收货单关联的U8单据ID列表，用于判断需要同步的U8单据
     *
     * @param wStartTime
     * @param wEndTime
     * @return
     */
    @Override
    public ServiceResult<List<Integer>> WMS_QueryReceiveBill_U8BillIDList(Calendar wStartTime, Calendar wEndTime) {
        ServiceResult<List<Integer>> wResult = new ServiceResult<>();

        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);
            wResult.Result = WMSReceiveBillDAO.getInstance().WMS_GetU8BillIDList(wStartTime, wEndTime, wErrorCode);
            wResult.AddFaultCode(wErrorCode);
        } catch (Exception ex) {
            wResult.FaultCode += ex.toString();
            logger.error(ex.toString());
        }

        return wResult;
    }
    //endregion

    //region 收货单子项

    /**
     * 批量保存收货单子项
     *
     * @param wLoginUser
     * @param wItemList
     * @return
     */
    @Override
    public ServiceResult<Integer> WMS_UpdateReceiveBillItemList(BMSEmployee wLoginUser,
                                                                List<WMSReceiveBillItem> wItemList) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);

        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            WMSReceiveBillItemDAO.getInstance().WMS_UpdateReceiveBillItemList(wLoginUser, wItemList, wErrorCode);
            if (wErrorCode.Result != 0) {
                wResult.AddFaultCode(wErrorCode);
                return wResult;
            }
            Calendar createTime = wItemList.stream().min(Comparator.comparingInt(o -> o.ID)).get().CreateTime;

            MRPDeliveryDAO.getInstance().MRP_UpdateDeliveryFQTYDone(wLoginUser,
                    createTime, Calendar.getInstance(), wErrorCode);
            wResult.AddFaultCode(wErrorCode);
        } catch (Exception ex) {
            wResult.FaultCode += ex.toString();
            logger.error(ex.toString());
        }

        return wResult;
    }

    /**
     * 添加或修改收货单子项
     *
     * @param wLoginUser
     * @param wItem
     * @return
     */
    @Override
    public ServiceResult<Integer> WMS_UpdateReceiveBillItem(BMSEmployee wLoginUser, WMSReceiveBillItem wItem) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);

        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            wResult.Result = WMSReceiveBillItemDAO.getInstance().WMS_UpdateReceiveBillItem(wLoginUser, wItem,
                    wErrorCode);
            if (wErrorCode.Result != 0) {
                wResult.AddFaultCode(wErrorCode);
                return wResult;
            }

            MRPDeliveryDAO.getInstance().MRP_UpdateDeliveryFQTYDone(wLoginUser,
                    wItem.CreateTime, Calendar.getInstance(), wErrorCode);
            wResult.AddFaultCode(wErrorCode);
        } catch (Exception ex) {
            wResult.FaultCode += ex.toString();
            logger.error(ex.toString());
        }

        return wResult;
    }

    /**
     * 删除单条收货单子项
     *
     * @param wLoginUser
     * @param wItem
     * @return
     */
    @Override
    public ServiceResult<Integer> WMS_DeleteReceiveBillItem(BMSEmployee wLoginUser, WMSReceiveBillItem wItem) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);

        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            WMSReceiveBillItemDAO.getInstance().DeletePO(wLoginUser, wItem, wErrorCode);
            if (wErrorCode.Result != 0) {
                wResult.AddFaultCode(wErrorCode);
                return wResult;
            }

            MRPDeliveryDAO.getInstance().MRP_UpdateDeliveryFQTYDone(wLoginUser,
                    wItem.CreateTime, Calendar.getInstance(), wErrorCode);
            wResult.AddFaultCode(wErrorCode);
        } catch (Exception ex) {
            wResult.FaultCode += ex.toString();
            logger.error(ex.toString());
        }

        return wResult;
    }

    /**
     * 批量删除收货单子项（传对象集合）
     *
     * @param wLoginUser
     * @param wItemList
     * @return
     */
    @Override
    public ServiceResult<Integer> WMS_DeleteReceiveBillItemList(BMSEmployee wLoginUser,
                                                                List<WMSReceiveBillItem> wItemList) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);

        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            WMSReceiveBillItemDAO.getInstance().DeletePOList(wLoginUser, wItemList, wErrorCode);
            if (wErrorCode.Result != 0) {
                wResult.AddFaultCode(wErrorCode);
                return wResult;
            }
            Calendar createTime = wItemList.stream().min(Comparator.comparingInt(o -> o.ID)).get().CreateTime;

            MRPDeliveryDAO.getInstance().MRP_UpdateDeliveryFQTYDone(wLoginUser,
                    createTime, Calendar.getInstance(), wErrorCode);
            wResult.AddFaultCode(wErrorCode);
        } catch (Exception ex) {
            wResult.FaultCode += ex.toString();
            logger.error(ex.toString());
        }

        return wResult;
    }

    /**
     * 批量删除收货单子项（传IDs）
     *
     * @param wLoginUser
     * @param wIDList
     * @return
     */
    @Override
    public ServiceResult<Integer> WMS_DeleteReceiveBillItemListByIDList(BMSEmployee wLoginUser, List<Integer> wIDList) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);

        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            List<WMSReceiveBillItem> wItemList = WMSReceiveBillItemDAO.getInstance().SelectPOList(wLoginUser, wIDList
                    , Pagination.getNewMaxSize(), wErrorCode);

            if (wErrorCode.Result != 0) {
                wResult.AddFaultCode(wErrorCode);
                return wResult;
            }

            WMSReceiveBillItemDAO.getInstance().DeletePOList(wLoginUser, wItemList, wErrorCode);
            if (wErrorCode.Result != 0) {
                wResult.AddFaultCode(wErrorCode);
                return wResult;
            }
            Calendar createTime = wItemList.stream().min(Comparator.comparingInt(o -> o.ID)).get().CreateTime;

            MRPDeliveryDAO.getInstance().MRP_UpdateDeliveryFQTYDone(wLoginUser,
                    createTime, Calendar.getInstance(), wErrorCode);
            wResult.AddFaultCode(wErrorCode);
        } catch (Exception ex) {
            wResult.FaultCode += ex.toString();
            logger.error(ex.toString());
        }

        return wResult;
    }


    /**
     * 用收货单主单据ID查子项集合
     *
     * @param wLoginUser
     * @param wReceiveBillID
     * @return
     */
    @Override
    public ServiceResult<List<WMSReceiveBillItem>> WMS_QueryReceiveBillItemListByReceiveBillID(BMSEmployee wLoginUser
            , int wReceiveBillID, Pagination wPagination) {
        ServiceResult<List<WMSReceiveBillItem>> wResult = new ServiceResult<>();

        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            wResult.Result = WMSReceiveBillItemDAO.getInstance().WMS_SelectListByReceiveBillID(wLoginUser,
                    wReceiveBillID, wPagination, wErrorCode);
            wResult.AddFaultCode(wErrorCode);
        } catch (Exception ex) {
            wResult.FaultCode += ex.toString();
            logger.error(ex.toString());
        }

        return wResult;
    }


    //endregion

    @Override
    public ServiceResult<List<WMSStoreStation>> WMS_CalcReceiveItemStation(
            BMSEmployee wLoginUser, WMSReceiveBillItem wWMSReceiveBillItem, MSSPackageProp wMSSPackageProp) {
        ServiceResult<List<WMSStoreStation>> wResult = new ServiceResult<>();
        wResult.Result = new ArrayList<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            MSSMaterial wMSSMaterial = MSSMaterialDAO.getInstance().SelectPO(
                    wLoginUser, -1, wWMSReceiveBillItem.MaterialCode, wErrorCode);
            if (wErrorCode.Result != 0) {
                wResult.FaultCode = ExceptionTypes.getEnumType(wErrorCode.Result).getLabel();
                return wResult;
            }
            if (wMSSMaterial == null || wMSSMaterial.ID <= 0) {
                wResult.FaultCode = StringUtils.Format("该物料({0})不存在", wWMSReceiveBillItem.MaterialCode);
                return wResult;
            }

            List<MSSMaterial> wMSSMaterialList = MSSMaterialDAO.getInstance().MSS_QueryMaterialList(wLoginUser, "", "",
                    -1, -1, -1, wMSSMaterial.MaterialGroupName, "", "", -1, -1, 1, Pagination.getMaxSize(),
                    wErrorCode);

            BRMShelvesRange wBRMShelvesRange = BRMShelvesRangeDAO.getInstance().BRM_QueryShelvesRange(wLoginUser,
                    wWMSReceiveBillItem.ReceiveStoreID, wWMSReceiveBillItem.CustomerID,
                    wWMSReceiveBillItem.MaterialCode, wErrorCode);
            if (wErrorCode.Result != 0) {
                wResult.FaultCode = ExceptionTypes.getEnumType(wErrorCode.Result).getLabel();
                return wResult;
            }

            if (wBRMShelvesRange.ID <= 0 || wBRMShelvesRange.RuleID <= 0) {

                wResult.FaultCode = StringUtils.Format("该物料({0})未设置上架规则", wWMSReceiveBillItem.MaterialCode);
                return wResult;
            }


            List<BRMShelvesProp> wShelvesPropList = BRMShelvesPropDAO.getInstance().BRM_QueryShelvesPropList(wLoginUser,
                    wBRMShelvesRange.RuleID, "", "", -1, Pagination.Create(1, Integer.MAX_VALUE, "Name", "ASC"),
                    wErrorCode);

            if (wErrorCode.Result != 0) {
                wResult.FaultCode = ExceptionTypes.getEnumType(wErrorCode.Result).getLabel();
                return wResult;
            }

            if (wShelvesPropList == null || wShelvesPropList.size() == 0) {
                wResult.FaultCode = StringUtils.Format("该物料({0})上架规则({1})为空", wWMSReceiveBillItem.MaterialCode,
                        wBRMShelvesRange.RuleCode);
                return wResult;
            }
            List<WMSStoreStation> wStoreStationList = WMSStoreStationDAO.getInstance().WMS_SelectStoreStationList(
                    wLoginUser, wWMSReceiveBillItem.ReceiveStoreID,
                    Pagination.getMaxSize(), wErrorCode);

            if (wErrorCode.Result != 0) {
                wResult.FaultCode = ExceptionTypes.getEnumType(wErrorCode.Result).getLabel();
                return wResult;
            }
            List<MSSMaterialStation> wMaterialStationList =
                    MSSMaterialStationDAO.getInstance().MSS_QueryMaterialStationList(wLoginUser,
                            wWMSReceiveBillItem.MaterialID, Pagination.getMaxSize(),
                            wErrorCode);
            if (wErrorCode.Result != 0) {
                wResult.FaultCode = ExceptionTypes.getEnumType(wErrorCode.Result).getLabel();
                return wResult;
            }

            List<WMSStock> wWMSStockList = WMSStockRecordDAO.getInstance().WMS_QueryStockCountList(wLoginUser,
                    -1, wWMSReceiveBillItem.ReceiveStoreID, -1, -1, -1, -1,
                    null, -1, "", "", -1, -1, -1, -1, 1, Pagination.getMaxSize(), wErrorCode);
            if (wErrorCode.Result != 0) {
                wResult.FaultCode = ExceptionTypes.getEnumType(wErrorCode.Result).getLabel();
                return wResult;
            }
            List<Integer> wStoreStationIDs = new ArrayList<>();
            ServiceResult<List<Integer>> wServiceResult;

            int wStepID = 0;


            double wMaterialNumber = wWMSReceiveBillItem.ReceiveQuantity;
            double wTotalVolume = wWMSReceiveBillItem.TotalVolume;
            double wTotalGrossWeight = wWMSReceiveBillItem.TotalGrossWeight;
            //包装属性为空 即为默认收货
            if (wMSSPackageProp == null || wMSSPackageProp.ID <= 0 || StringUtils.isEmpty(wMSSPackageProp.Code)) {
                wMSSPackageProp = MSSPackagePropDAO.getInstance().MSS_QueryPackageProp(
                        wLoginUser, -1, wWMSReceiveBillItem.PackageRuleCode, wWMSReceiveBillItem.ReceiveUnitText,
                        wErrorCode);
                if (wErrorCode.Result != 0) {
                    wResult.FaultCode = ExceptionTypes.getEnumType(wErrorCode.Result).getLabel();
                    return wResult;
                }
            }
            if (wMSSPackageProp.MaterialNumber > wMaterialNumber) {
                wMaterialNumber = wMSSPackageProp.MaterialNumber;
            }
            if (wMSSPackageProp.Volume > wTotalVolume) {
                wTotalVolume = wMSSPackageProp.Volume;
            }
            if ((wMSSPackageProp.Weight + wMSSMaterial.GrossWeight * wMaterialNumber) > wTotalGrossWeight) {
                wTotalGrossWeight = (wMSSPackageProp.Weight + wMSSMaterial.GrossWeight * wMaterialNumber);
            }

            for (BRMShelvesProp wShelvesProp : wShelvesPropList) {

                if (wStepID > 0 && wShelvesProp.ID != wStepID) {
                    continue;
                }
                wStepID = 0;

                wServiceResult = this.WMS_CalcReceiveItemStation(wLoginUser, wWMSReceiveBillItem, wMaterialStationList,
                        wShelvesProp, wMSSPackageProp, wMSSMaterial, wMSSMaterialList, wMaterialNumber, wTotalVolume,
                        wTotalGrossWeight, wWMSStockList, wStoreStationList);
                if (StringUtils.isEmpty(wServiceResult.FaultCode) && wServiceResult.Result != null &&
                        wServiceResult.Result.size() > 0) {
                    //success

                    //OR
                    for (Integer wmsStoreStationID : wServiceResult.Result) {
                        if (wStoreStationIDs.contains(wmsStoreStationID)) {
                            continue;
                        }
                        wStoreStationIDs.add(wmsStoreStationID);
                    }
                    if (wShelvesProp.SuccessStepID > 0) {
                        wStepID = wShelvesProp.SuccessStepID;
                    } else {
                        break;
                    }
                } else if (wShelvesProp.ErrorStepID > 0) {
                    wStepID = wShelvesProp.ErrorStepID;
                }
            }

        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<List<Integer>> WMS_CalcReceiveItemStation(
            BMSEmployee wLoginUser, WMSReceiveBillItem wWMSReceiveBillItem,
            List<MSSMaterialStation> wMaterialStationList,
            BRMShelvesProp wBRMShelvesProp, MSSPackageProp wMSSPackageProp, MSSMaterial wMSSMaterial,
            List<MSSMaterial> wMSSMaterialList, double wMaterialNumber, double wTotalVolume, double wTotalGrossWeight,
            List<WMSStock> wStockList, List<WMSStoreStation> wStoreStationList) {
        ServiceResult<List<Integer>> wResult = new ServiceResult<>();
        wResult.Result = new ArrayList<>();
        try {
            if (wWMSReceiveBillItem == null || wBRMShelvesProp == null || wWMSReceiveBillItem.ID <= 0 ||
                    wBRMShelvesProp.ID <= 0 || wBRMShelvesProp.TypeID <= 0 || wBRMShelvesProp.Active != 1) {
                return wResult;
            }


            BRMShelvesTypes wBRMShelvesTypes = BRMShelvesTypes.getEnumType(wBRMShelvesProp.TypeID);
            if (wBRMShelvesTypes == BRMShelvesTypes.Default) {
                return wResult;
            }
            List<WMSStoreStation> wWMSStoreStationList;
            Map<Integer, WMSStoreStation> wStoreStationMap;
            List<Integer> wMaterialStationIDList;
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            //计算
            switch (wBRMShelvesTypes) {
                case Code01:
                    if (wBRMShelvesProp.OriginalStationID == wWMSReceiveBillItem.ReceiveStationID) {
                        wResult.Result.add(wBRMShelvesProp.TargetStationID);
                    }
                    break;
                case Code02:
                    if (wBRMShelvesProp.OriginalStationID == wWMSReceiveBillItem.ReceiveStationID) {
                        //获取某库区下所有库位
                        wWMSStoreStationList = wStoreStationList.stream().filter(
                                p -> p.StoreAreaID == wBRMShelvesProp.StoreAreaID).collect(Collectors.toList());

                        //进行库位限制与体积限制判断
                        wWMSStoreStationList = BRMShelvesPropDAO.getInstance().BRM_CalcReceiveItemStation(wLoginUser,
                                wWMSStoreStationList, wMaterialStationList, wStockList, wBRMShelvesProp,
                                wMSSPackageProp, wWMSReceiveBillItem.BillType, wWMSReceiveBillItem.ReceiveUnitText, 0,
                                wWMSReceiveBillItem.BatchRuleCode, wMSSMaterial, wMSSMaterialList,
                                wWMSReceiveBillItem.BatchRecordCode, wMaterialNumber, wTotalVolume, wTotalGrossWeight,
                                wErrorCode);


                        wResult.Result.addAll(wWMSStoreStationList.stream().map(p -> p.ID).distinct()
                                .collect(Collectors.toList()));

                    }
                    break;
                case Code08:
                    if (wBRMShelvesProp.OriginalStationID == wWMSReceiveBillItem.ReceiveStationID) {
                        //获取某货架下所有库位
                        wWMSStoreStationList = wStoreStationList.stream().filter(
                                p -> p.StoreShelfID == wBRMShelvesProp.TargetShelfID).collect(Collectors.toList());

                        //进行库位限制与体积限制判断
                        wWMSStoreStationList = BRMShelvesPropDAO.getInstance().BRM_CalcReceiveItemStation(wLoginUser,
                                wWMSStoreStationList, wMaterialStationList, wStockList, wBRMShelvesProp,
                                wMSSPackageProp, wWMSReceiveBillItem.BillType, wWMSReceiveBillItem.ReceiveUnitText, 0,
                                wWMSReceiveBillItem.BatchRuleCode, wMSSMaterial, wMSSMaterialList,
                                wWMSReceiveBillItem.BatchRecordCode, wMaterialNumber, wTotalVolume, wTotalGrossWeight,
                                wErrorCode);
                        wResult.Result.addAll(wWMSStoreStationList.stream().map(p -> p.ID).distinct()
                                .collect(Collectors.toList()));

                    }
                    break;
                case Code03:
                    //获取某库区下所有库位
                    wWMSStoreStationList = wStoreStationList.stream().filter(
                            p -> p.StoreAreaID == wBRMShelvesProp.StoreAreaID).collect(Collectors.toList());


                    //进行库位限制与体积限制判断
                    wWMSStoreStationList = BRMShelvesPropDAO.getInstance().BRM_CalcReceiveItemStation(wLoginUser,
                            wWMSStoreStationList, wMaterialStationList, wStockList, wBRMShelvesProp, wMSSPackageProp,
                            wWMSReceiveBillItem.BillType, wWMSReceiveBillItem.ReceiveUnitText, 0,
                            wWMSReceiveBillItem.BatchRuleCode,
                            wMSSMaterial, wMSSMaterialList, wWMSReceiveBillItem.BatchRecordCode, wMaterialNumber,
                            wTotalVolume, wTotalGrossWeight, wErrorCode);


                    wResult.Result.addAll(wWMSStoreStationList.stream().map(p -> p.ID).distinct()
                            .collect(Collectors.toList()));
                    break;
                case Code09:
                    //获取某货架下所有库位
                    wWMSStoreStationList = wStoreStationList.stream().filter(
                            p -> p.StoreShelfID == wBRMShelvesProp.TargetShelfID).collect(Collectors.toList());

                    //进行库位限制与体积限制判断
                    wWMSStoreStationList = BRMShelvesPropDAO.getInstance().BRM_CalcReceiveItemStation(wLoginUser,
                            wWMSStoreStationList, wMaterialStationList, wStockList, wBRMShelvesProp, wMSSPackageProp,
                            wWMSReceiveBillItem.BillType, wWMSReceiveBillItem.ReceiveUnitText, 0,
                            wWMSReceiveBillItem.BatchRuleCode,
                            wMSSMaterial, wMSSMaterialList, wWMSReceiveBillItem.BatchRecordCode, wMaterialNumber,
                            wTotalVolume, wTotalGrossWeight, wErrorCode);

                    wResult.Result.addAll(wWMSStoreStationList.stream().map(p -> p.ID).distinct()
                            .collect(Collectors.toList()));
                    break;
                case Code04:

                    wResult.Result.add(wBRMShelvesProp.TargetStationID);

                    break;
                case Code06:
                    //获取物料可存放库位以及推荐存放库位
                    wMaterialStationIDList = wMaterialStationList.stream().sorted(
                            (o1, o2) -> (o2.Recommend & 1) == 1 && (o1.Recommend & 1) != 1 ? 1 : 0).map(
                            p -> p.StoreStationID).distinct().collect(Collectors.toList());

                    wWMSStoreStationList = new ArrayList<>();
                    wStoreStationMap = wStoreStationList.stream().collect(Collectors.toMap(p -> p.ID, p -> p));
                    for (Integer wMaterialStationID : wMaterialStationIDList) {
                        if (wStoreStationMap.containsKey(wMaterialStationID)) {
                            wWMSStoreStationList.add(wStoreStationMap.get(wMaterialStationID));
                        }
                    }
                    //进行库位限制与体积限制判断
                    wWMSStoreStationList = BRMShelvesPropDAO.getInstance().BRM_CalcReceiveItemStation(wLoginUser,
                            wWMSStoreStationList, wMaterialStationList, wStockList, wBRMShelvesProp, wMSSPackageProp,
                            wWMSReceiveBillItem.BillType, wWMSReceiveBillItem.ReceiveUnitText, 0,
                            wWMSReceiveBillItem.BatchRuleCode,
                            wMSSMaterial, wMSSMaterialList, wWMSReceiveBillItem.BatchRecordCode, wMaterialNumber,
                            wTotalVolume, wTotalGrossWeight, wErrorCode);

                    wResult.Result.addAll(wWMSStoreStationList.stream().map(p -> p.ID).distinct()
                            .collect(Collectors.toList()));
                    break;
                case Code07:
                    //获取物料可存放库位以及推荐存放库位
                    wMaterialStationIDList = wMaterialStationList.stream().filter(p -> (p.Recommend & 1) == 1).map(
                            p -> p.StoreStationID).distinct().collect(Collectors.toList());

                    wWMSStoreStationList = new ArrayList<>();

                    wStoreStationMap = wStoreStationList.stream().collect(Collectors.toMap(p -> p.ID, p -> p));
                    for (Integer wMaterialStationID : wMaterialStationIDList) {
                        if (wStoreStationMap.containsKey(wMaterialStationID)) {
                            wWMSStoreStationList.add(wStoreStationMap.get(wMaterialStationID));
                        }
                    }
                    //进行库位限制与体积限制判断
                    wWMSStoreStationList = BRMShelvesPropDAO.getInstance().BRM_CalcReceiveItemStation(wLoginUser,
                            wWMSStoreStationList, wMaterialStationList, wStockList, wBRMShelvesProp, wMSSPackageProp,
                            wWMSReceiveBillItem.BillType, wWMSReceiveBillItem.ReceiveUnitText, 0,
                            wWMSReceiveBillItem.BatchRuleCode,
                            wMSSMaterial, wMSSMaterialList, wWMSReceiveBillItem.BatchRecordCode, wMaterialNumber,
                            wTotalVolume, wTotalGrossWeight, wErrorCode);

                    wResult.Result.addAll(wWMSStoreStationList.stream().map(p -> p.ID).distinct()
                            .collect(Collectors.toList()));


                    break;
                case Code11:
                    //获取物料可存放库位以及推荐存放库位
                    wMaterialStationIDList = wMaterialStationList.stream().filter(p -> (p.Recommend & 2) == 2).map(
                            p -> p.StoreStationID).distinct().collect(Collectors.toList());

                    wWMSStoreStationList = new ArrayList<>();

                    wStoreStationMap = wStoreStationList.stream().collect(Collectors.toMap(p -> p.ID, p -> p));
                    for (Integer wMaterialStationID : wMaterialStationIDList) {
                        if (wStoreStationMap.containsKey(wMaterialStationID) && wStoreStationMap.get(
                                wMaterialStationID).PickingMode == WMSPickingMode.PC.getValue()) {
                            wWMSStoreStationList.add(wStoreStationMap.get(wMaterialStationID));
                        }
                    }
                    //进行库位限制与体积限制判断
                    wWMSStoreStationList = BRMShelvesPropDAO.getInstance().BRM_CalcReceiveItemStation(wLoginUser,
                            wWMSStoreStationList, wMaterialStationList, wStockList, wBRMShelvesProp, wMSSPackageProp,
                            wWMSReceiveBillItem.BillType, wWMSReceiveBillItem.ReceiveUnitText, 0,
                            wWMSReceiveBillItem.BatchRuleCode,
                            wMSSMaterial, wMSSMaterialList, wWMSReceiveBillItem.BatchRecordCode, wMaterialNumber,
                            wTotalVolume, wTotalGrossWeight, wErrorCode);

                    wResult.Result.addAll(wWMSStoreStationList.stream().map(p -> p.ID).distinct()
                            .collect(Collectors.toList()));
                    break;
                case Code12:
                    //获取物料可存放库位以及推荐存放库位
                    wMaterialStationIDList = wMaterialStationList.stream().filter(p -> (p.Recommend & 2) == 2).map(
                            p -> p.StoreStationID).distinct().collect(Collectors.toList());

                    wWMSStoreStationList = new ArrayList<>();

                    wStoreStationMap = wStoreStationList.stream().collect(Collectors.toMap(p -> p.ID, p -> p));
                    for (Integer wMaterialStationID : wMaterialStationIDList) {
                        if (wStoreStationMap.containsKey(wMaterialStationID) && wStoreStationMap.get(
                                wMaterialStationID).PickingMode == WMSPickingMode.Box.getValue()) {
                            wWMSStoreStationList.add(wStoreStationMap.get(wMaterialStationID));
                        }
                    }
                    //进行库位限制与体积限制判断
                    wWMSStoreStationList = BRMShelvesPropDAO.getInstance().BRM_CalcReceiveItemStation(wLoginUser,
                            wWMSStoreStationList, wMaterialStationList, wStockList, wBRMShelvesProp, wMSSPackageProp,
                            wWMSReceiveBillItem.BillType, wWMSReceiveBillItem.ReceiveUnitText, 0,
                            wWMSReceiveBillItem.BatchRuleCode,
                            wMSSMaterial, wMSSMaterialList, wWMSReceiveBillItem.BatchRecordCode, wMaterialNumber,
                            wTotalVolume, wTotalGrossWeight, wErrorCode);

                    wResult.Result.addAll(wWMSStoreStationList.stream().map(p -> p.ID).distinct()
                            .collect(Collectors.toList()));
                    break;
                case Code13:
                    //获取物料可存放库位以及推荐存放库位
                    wMaterialStationIDList = wMaterialStationList.stream().filter(p -> (p.Recommend & 2) == 2).map(
                            p -> p.StoreStationID).distinct().collect(Collectors.toList());

                    wWMSStoreStationList = new ArrayList<>();

                    wStoreStationMap = wStoreStationList.stream().collect(Collectors.toMap(p -> p.ID, p -> p));
                    for (Integer wMaterialStationID : wMaterialStationIDList) {
                        if (wStoreStationMap.containsKey(wMaterialStationID) && wStoreStationMap.get(
                                wMaterialStationID).PickingMode == WMSPickingMode.PCORBox.getValue()) {
                            wWMSStoreStationList.add(wStoreStationMap.get(wMaterialStationID));
                        }
                    }
                    //进行库位限制与体积限制判断
                    wWMSStoreStationList = BRMShelvesPropDAO.getInstance().BRM_CalcReceiveItemStation(wLoginUser,
                            wWMSStoreStationList, wMaterialStationList, wStockList, wBRMShelvesProp, wMSSPackageProp,
                            wWMSReceiveBillItem.BillType, wWMSReceiveBillItem.ReceiveUnitText, 0,
                            wWMSReceiveBillItem.BatchRuleCode,
                            wMSSMaterial, wMSSMaterialList, wWMSReceiveBillItem.BatchRecordCode, wMaterialNumber,
                            wTotalVolume, wTotalGrossWeight, wErrorCode);

                    wResult.Result.addAll(wWMSStoreStationList.stream().map(p -> p.ID).distinct()
                            .collect(Collectors.toList()));
                    break;

                case Code21:
                    if (CalendarTool.getDate(wWMSReceiveBillItem.ProductDate).compareTo(
                            CalendarTool.getDate(wBRMShelvesProp.ProductDate)) == 0 && CalendarTool.getDate(
                            wWMSReceiveBillItem.ExpireDate).compareTo(CalendarTool.getDate(wBRMShelvesProp.ExpireDate)) ==
                            0 && CalendarTool.getDate(
                            wWMSReceiveBillItem.StockDate).compareTo(CalendarTool.getDate(wBRMShelvesProp.StockDate)) ==
                            0 &&
                            wWMSReceiveBillItem.LotAttr04.equals(wBRMShelvesProp.LotAttr04) && wWMSReceiveBillItem.LotAttr05.equals(
                            wBRMShelvesProp.LotAttr05) && wWMSReceiveBillItem.LotAttr06.equals(wBRMShelvesProp.LotAttr06) &&
                            wWMSReceiveBillItem.LotAttr07.equals(wBRMShelvesProp.LotAttr07) && wWMSReceiveBillItem.LotAttr08.equals(
                            wBRMShelvesProp.LotAttr08) && wWMSReceiveBillItem.LotAttr09.equals(wBRMShelvesProp.LotAttr09) &&
                            wWMSReceiveBillItem.LotAttr10.equals(wBRMShelvesProp.LotAttr10) && wWMSReceiveBillItem.LotAttr11.equals(
                            wBRMShelvesProp.LotAttr11) && wWMSReceiveBillItem.LotAttr12.equals(wBRMShelvesProp.LotAttr12)) {


                        //获取某库区下所有库位
                        wWMSStoreStationList = wStoreStationList.stream().filter(
                                p -> p.StoreAreaID == wBRMShelvesProp.StoreAreaID).collect(Collectors.toList());


                        //进行库位限制与体积限制判断
                        wWMSStoreStationList = BRMShelvesPropDAO.getInstance().BRM_CalcReceiveItemStation(wLoginUser,
                                wWMSStoreStationList, wMaterialStationList, wStockList, wBRMShelvesProp,
                                wMSSPackageProp, wWMSReceiveBillItem.BillType, wWMSReceiveBillItem.ReceiveUnitText, 0,
                                wWMSReceiveBillItem.BatchRuleCode, wMSSMaterial, wMSSMaterialList,
                                wWMSReceiveBillItem.BatchRecordCode, wMaterialNumber, wTotalVolume, wTotalGrossWeight,
                                wErrorCode);


                        wResult.Result.addAll(wWMSStoreStationList.stream().map(p -> p.ID).distinct()
                                .collect(Collectors.toList()));
                    }

                    break;
                case Code22:
                    if (CalendarTool.getDate(wWMSReceiveBillItem.ProductDate).compareTo(
                            CalendarTool.getDate(wBRMShelvesProp.ProductDate)) == 0 && CalendarTool.getDate(
                            wWMSReceiveBillItem.ExpireDate).compareTo(CalendarTool.getDate(wBRMShelvesProp.ExpireDate)) ==
                            0 && CalendarTool.getDate(
                            wWMSReceiveBillItem.StockDate).compareTo(CalendarTool.getDate(wBRMShelvesProp.StockDate)) ==
                            0 &&
                            wWMSReceiveBillItem.LotAttr04.equals(wBRMShelvesProp.LotAttr04) && wWMSReceiveBillItem.LotAttr05.equals(
                            wBRMShelvesProp.LotAttr05) && wWMSReceiveBillItem.LotAttr06.equals(wBRMShelvesProp.LotAttr06) &&
                            wWMSReceiveBillItem.LotAttr07.equals(wBRMShelvesProp.LotAttr07) && wWMSReceiveBillItem.LotAttr08.equals(
                            wBRMShelvesProp.LotAttr08) && wWMSReceiveBillItem.LotAttr09.equals(wBRMShelvesProp.LotAttr09) &&
                            wWMSReceiveBillItem.LotAttr10.equals(wBRMShelvesProp.LotAttr10) && wWMSReceiveBillItem.LotAttr11.equals(
                            wBRMShelvesProp.LotAttr11) && wWMSReceiveBillItem.LotAttr12.equals(wBRMShelvesProp.LotAttr12)) {


                        wResult.Result.add(wBRMShelvesProp.TargetStationID);


                    }
                    break;
                case Code23:
                    if (CalendarTool.getDate(wWMSReceiveBillItem.ProductDate).compareTo(
                            CalendarTool.getDate(wBRMShelvesProp.ProductDate)) == 0 && CalendarTool.getDate(
                            wWMSReceiveBillItem.ExpireDate).compareTo(CalendarTool.getDate(wBRMShelvesProp.ExpireDate)) ==
                            0 && CalendarTool.getDate(
                            wWMSReceiveBillItem.StockDate).compareTo(CalendarTool.getDate(wBRMShelvesProp.StockDate)) ==
                            0 &&
                            wWMSReceiveBillItem.LotAttr04.equals(wBRMShelvesProp.LotAttr04) && wWMSReceiveBillItem.LotAttr05.equals(
                            wBRMShelvesProp.LotAttr05) && wWMSReceiveBillItem.LotAttr06.equals(wBRMShelvesProp.LotAttr06) &&
                            wWMSReceiveBillItem.LotAttr07.equals(wBRMShelvesProp.LotAttr07) && wWMSReceiveBillItem.LotAttr08.equals(
                            wBRMShelvesProp.LotAttr08) && wWMSReceiveBillItem.LotAttr09.equals(wBRMShelvesProp.LotAttr09) &&
                            wWMSReceiveBillItem.LotAttr10.equals(wBRMShelvesProp.LotAttr10) && wWMSReceiveBillItem.LotAttr11.equals(
                            wBRMShelvesProp.LotAttr11) && wWMSReceiveBillItem.LotAttr12.equals(wBRMShelvesProp.LotAttr12)) {

                        wWMSStoreStationList = wStoreStationList.stream().filter(
                                p -> p.StoreShelfID == wBRMShelvesProp.TargetShelfID).collect(Collectors.toList());

                        //进行库位限制与体积限制判断
                        wWMSStoreStationList = BRMShelvesPropDAO.getInstance().BRM_CalcReceiveItemStation(wLoginUser,
                                wWMSStoreStationList, wMaterialStationList, wStockList, wBRMShelvesProp,
                                wMSSPackageProp, wWMSReceiveBillItem.BillType, wWMSReceiveBillItem.ReceiveUnitText, 0,
                                wWMSReceiveBillItem.BatchRuleCode, wMSSMaterial, wMSSMaterialList,
                                wWMSReceiveBillItem.BatchRecordCode, wMaterialNumber, wTotalVolume, wTotalGrossWeight,
                                wErrorCode);
                        wResult.Result.addAll(wWMSStoreStationList.stream().map(p -> p.ID).distinct()
                                .collect(Collectors.toList()));
                    }
                    break;
                case Code30:

                    //获取本物料可存放库位
                    wMaterialStationIDList = wMaterialStationList.stream().sorted(
                            (o1, o2) -> (o2.Recommend & 2) == 2 && (o1.Recommend & 2) != 2 ? 1 : 0).map(
                            p -> p.StoreStationID).distinct().collect(Collectors.toList());

                    wWMSStoreStationList = new ArrayList<>();
                    wStoreStationMap = wStoreStationList.stream().collect(Collectors.toMap(p -> p.ID, p -> p));
                    for (Integer wMaterialStationID : wMaterialStationIDList) {
                        if (wStoreStationMap.containsKey(wMaterialStationID)) {
                            wWMSStoreStationList.add(wStoreStationMap.get(wMaterialStationID));
                        }
                    }

                    //进行库位限制与体积限制判断
                    wWMSStoreStationList = BRMShelvesPropDAO.getInstance().BRM_CalcReceiveItemStation(wLoginUser,
                            wWMSStoreStationList, wMaterialStationList, wStockList, wBRMShelvesProp, wMSSPackageProp,
                            wWMSReceiveBillItem.BillType, wWMSReceiveBillItem.ReceiveUnitText, 0,
                            wWMSReceiveBillItem.BatchRuleCode,
                            wMSSMaterial, wMSSMaterialList, wWMSReceiveBillItem.BatchRecordCode, wMaterialNumber,
                            wTotalVolume, wTotalGrossWeight, wErrorCode);

                    //根据库存同组产品所在库存库位进行远近排序
                    wWMSStoreStationList = BRMShelvesPropDAO.getInstance().BRM_SortReceiveItemStation(wLoginUser,
                            wWMSStoreStationList, wMSSMaterialList, wStockList, wStoreStationList, wErrorCode);


                    wResult.Result.addAll(wWMSStoreStationList.stream().map(p -> p.ID).distinct()
                            .collect(Collectors.toList()));

                    break;
                case Code31:
                    //获取物料可存放库位以及推荐存放库位
                    wMaterialStationIDList = wMaterialStationList.stream().sorted(
                            (o1, o2) -> (o2.Recommend & 2) == 2 && (o1.Recommend & 2) != 2 ? 1 : 0).map(
                            p -> p.StoreStationID).distinct().collect(Collectors.toList());

                    wWMSStoreStationList = new ArrayList<>();
                    wStoreStationMap = wStoreStationList.stream().collect(Collectors.toMap(p -> p.ID, p -> p));
                    for (Integer wMaterialStationID : wMaterialStationIDList) {
                        if (wStoreStationMap.containsKey(wMaterialStationID)) {
                            wWMSStoreStationList.add(wStoreStationMap.get(wMaterialStationID));
                        }
                    }

                    //进行库位限制与体积限制判断
                    wWMSStoreStationList = BRMShelvesPropDAO.getInstance().BRM_CalcReceiveItemStation(wLoginUser,
                            wWMSStoreStationList, wMaterialStationList, wStockList, wBRMShelvesProp, wMSSPackageProp,
                            wWMSReceiveBillItem.BillType, wWMSReceiveBillItem.ReceiveUnitText, 0,
                            wWMSReceiveBillItem.BatchRuleCode,
                            wMSSMaterial, wMSSMaterialList, wWMSReceiveBillItem.BatchRecordCode, wMaterialNumber,
                            wTotalVolume, wTotalGrossWeight, wErrorCode);


                    wMaterialStationIDList = wMaterialStationList.stream().filter(p -> (p.Recommend & 2) == 2).map(
                            p -> p.StoreStationID).distinct().collect(Collectors.toList());

                    //根据离拣货位的距离排序
                    wWMSStoreStationList = BRMShelvesPropDAO.getInstance().BRM_SortReceiveItemStation(
                            wLoginUser, wWMSStoreStationList, wWMSStoreStationList, wErrorCode);


                    wResult.Result.addAll(wWMSStoreStationList.stream().map(p -> p.ID).distinct()
                            .collect(Collectors.toList()));
                    break;
                default:
                    return wResult;
            }


        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<Integer> WMS_UpdateInspectTask(BMSEmployee wLoginUser, WMSInspectTask wInspectTask) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);


            wResult.Result = WMSInspectTaskDAO.getInstance().WMS_UpdateInspectTask(
                    wLoginUser, wInspectTask, wErrorCode);

            wResult.AddFaultCode(wErrorCode);
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<Integer> WMS_DeleteInspectTaskList(
            BMSEmployee wLoginUser, List<WMSInspectTask> wInspectTaskList) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            WMSInspectTaskDAO.getInstance().DeletePOList(wLoginUser, wInspectTaskList, wErrorCode);

            wResult.AddFaultCode(wErrorCode);
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<List<WMSInspectTask>> WMS_QueryInspectTaskList(
            BMSEmployee wLoginUser, String wPurchaseOrderCode, String wPurchaseOrderItemCode, String wArrivalNoticeCode,
            String wArrivalNoticeItemCode, int wTypeID, int wNoticeStatus, int wNoticeItemStatus, int wInspectorID,
            int wInspectResult, int wStoreID, String wStoreCode, int wCustomerID, String wCustomerCode, int wSupplierID,
            String wSupplierCode, String wMaterialNo, String wMaterialName, int wCreatorID, int wActive,
            Calendar wStartTime, Calendar wEndTime, Pagination wPagination) {
        ServiceResult<List<WMSInspectTask>> wResult = new ServiceResult<List<WMSInspectTask>>();
        wResult.Result = new ArrayList<WMSInspectTask>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            wResult.Result = WMSInspectTaskDAO.getInstance().WMS_QueryInspectTaskList(wLoginUser, wPurchaseOrderCode,
                    wPurchaseOrderItemCode, wArrivalNoticeCode, wArrivalNoticeItemCode, wTypeID, wNoticeStatus,
                    wNoticeItemStatus, wInspectorID, wInspectResult, wStoreID, wStoreCode, wCustomerID, wCustomerCode,
                    wSupplierID, wSupplierCode, wMaterialNo, wMaterialName, wCreatorID, wActive, wStartTime, wEndTime
                    , wPagination,
                    wErrorCode);

            wResult.AddFaultCode(wErrorCode);
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<WMSInspectTask> WMS_QueryInspectTask(BMSEmployee wLoginUser, int wID, String wCode) {
        ServiceResult<WMSInspectTask> wResult = new ServiceResult<WMSInspectTask>();
        wResult.Result = new WMSInspectTask();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            wResult.Result = WMSInspectTaskDAO.getInstance().WMS_QueryInspectTask(wLoginUser, wID, wCode, wErrorCode);

            wResult.AddFaultCode(wErrorCode);
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<Integer> WMS_UpdateInspectTaskItemList(
            BMSEmployee wLoginUser, List<WMSInspectTaskItem> wWMSInspectTaskItemList) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            for (WMSInspectTaskItem wWMSInspectTaskItem : wWMSInspectTaskItemList) {
                WMSInspectTaskItemDAO.getInstance().WMS_UpdateInspectTaskItem(
                        wLoginUser, wWMSInspectTaskItem, wErrorCode);
            }

            wResult.AddFaultCode(wErrorCode);
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<Integer> WMS_DeleteInspectTaskItemList(
            BMSEmployee wLoginUser, List<WMSInspectTaskItem> wInspectTaskItemList) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);


            WMSInspectTaskItemDAO.getInstance().WMS_DeleteInspectTaskItemList(
                    wLoginUser, wInspectTaskItemList, wErrorCode);

            wResult.AddFaultCode(wErrorCode);
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<List<WMSInspectTaskItem>> WMS_QueryInspectTaskItemList(
            BMSEmployee wLoginUser, String wPurchaseOrderCode, String wPurchaseOrderItemCode, String wArrivalNoticeCode,
            String wArrivalNoticeItemCode, int wTypeID, int wIPTStatus, int wInspectorID, int wInspectResult,
            int wStoreID, String wStoreCode, String wMaterialNo, String wMaterialName, int wActive, Calendar wStartTime,
            Calendar wEndTime, Pagination wPagination) {
        ServiceResult<List<WMSInspectTaskItem>> wResult = new ServiceResult<List<WMSInspectTaskItem>>();
        wResult.Result = new ArrayList<WMSInspectTaskItem>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            wResult.Result = WMSInspectTaskItemDAO.getInstance().WMS_QueryInspectTaskItemList(wLoginUser,
                    wPurchaseOrderCode, wPurchaseOrderItemCode, wArrivalNoticeCode, wArrivalNoticeItemCode, wTypeID,
                    wIPTStatus, wInspectorID, wInspectResult, wStoreID, wStoreCode, wMaterialNo, wMaterialName, wActive,
                    wStartTime, wEndTime, wPagination, wErrorCode);

            wResult.AddFaultCode(wErrorCode);
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<WMSInspectTaskItem> WMS_QueryInspectTaskItem(BMSEmployee wLoginUser, int wID, String wCode) {
        ServiceResult<WMSInspectTaskItem> wResult = new ServiceResult<>();
        wResult.Result = new WMSInspectTaskItem();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            wResult.Result = WMSInspectTaskItemDAO.getInstance().WMS_QueryInspectTaskItem(
                    wLoginUser, wID, wCode, wErrorCode);

            wResult.AddFaultCode(wErrorCode);
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<WMSInspectTask> WMS_CreateInspectTask(BMSEmployee wLoginUser,
                                                               WMSArrivalNoticeItem wWMSArrivalNoticeItem) {
        ServiceResult<WMSInspectTask> wResult = new ServiceResult<>();
        wResult.Result = new WMSInspectTask();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

//            wResult.Result = WMSInspectTaskDAO.getInstance().WMS_CreateInspectTask(
//                    wLoginUser, wWMSArrivalNoticeItem, wErrorCode);

            wResult.AddFaultCode(wErrorCode);
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error("WMS_CreateReceiveRecord", e);
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<WMSArrivalNoticeItemImpo>> ASN_ImportArrivalNoticeItems(BMSEmployee wLoginUser,
                                                                                      ExcelData wExcelData) {
        ServiceResult<List<WMSArrivalNoticeItemImpo>> wResult = new ServiceResult<>();
        wResult.Result = new ArrayList<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            if (wExcelData == null || wExcelData.sheetData == null || wExcelData.sheetData.size() <= 0) {
                wResult.FaultCode += "导入失败：Excel格式错误!!!";
                return wResult;
            }

            ExcelSheetData wExcelSheetData = wExcelData.sheetData.get(0);
            if (wExcelSheetData.lineData == null || wExcelSheetData.lineData.size() <= 1) {
                wResult.FaultCode += "导入失败：Excel无内容!!!";
                return wResult;
            }

            //①物料信息
            Map<String, Object> wParams = new HashMap<String, Object>();
            List<MSSMaterial> wMSSMaterialList = mMSSMaterialService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wMSSMaterialList == null || wMSSMaterialList.size() <= 0) {
                wResult.FaultCode += "导入失败：未获取到物料主数据信息!!!";
                return wResult;
            }
//            Map<String, Integer> wCodeIDMaterialMap =
//                    wMSSMaterialList.stream().collect(Collectors.toMap(MSSMaterial::getCode
//                            , MSSMaterial::getID));

            //②计量单位
            List<MSSUnit> wMSSUnitList = mMSSUnitService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wMSSUnitList == null || wMSSUnitList.size() <= 0) {
                wResult.FaultCode += "导入失败：未获取到计量单位信息!!!";
                return wResult;
            }

            Map<String, Integer> wNameIDUnitMap =
                    wMSSUnitList.stream().collect(Collectors.toMap(MSSUnit::getName
                            , MSSUnit::getID));

            WMSArrivalNoticeItemImpo wHeadInfo = GetHeadInfo(wLoginUser, wExcelSheetData.lineData, wErrorCode);

            WMSArrivalNoticeItemImpo wWMSArrivalNoticeItemImpo;
            ExcelLineData wExcelLineData;
            for (int i = 0; i < wExcelSheetData.lineData.size(); i++) {
                if (i <= 7) {
                    continue;
                }

                wExcelLineData = wExcelSheetData.lineData.get(i);

                if (wExcelLineData.colData.size() < 2) {
                    continue;
                }
                //判断第二列是否为数字类型的字符串，若不是，则跳过
                String wNumberCol = wExcelLineData.colData.get(1);
                if (StringUtils.isEmpty(wNumberCol) || StringUtils.parseInt(wNumberCol) <= 0) {
                    continue;
                }

                int wIndex = 2;

                if(StringUtils.parseInt(wNumberCol)==21){
                    int ss=0;
                }

                //物料编码
                String wCol1 = wExcelLineData.colData.get(2);
                //物料名称
                String wCol2 = wExcelLineData.colData.get(4);
                //规则型号
                String wCol3 = wExcelLineData.colData.get(5);
                //实发数量
                String wCol4 = wExcelLineData.colData.get(9);
                //生产订单号
                String wCol5 = wExcelLineData.colData.get(10);
                //计量单位
                String wCol6 = wExcelLineData.colData.get(16);
                //备注
                String wCol7 = wExcelLineData.colData.size() >= 18 ? wExcelLineData.colData.get(17) : "";

                wWMSArrivalNoticeItemImpo = new WMSArrivalNoticeItemImpo(wHeadInfo.StoreCode, wHeadInfo.StoreName,
                        wHeadInfo.ProjectName,
                        wCol1, wCol2, wCol3, StringUtils.parseFloat(wCol4), wCol5, wCol6, wCol7);
                wResult.Result.add(wWMSArrivalNoticeItemImpo);
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error("ASN_ImportArrivalNoticeItems", e);
        }
        return wResult;
    }

    /**
     * 获取表头信息
     */
    private WMSArrivalNoticeItemImpo GetHeadInfo(BMSEmployee wLoginUser, List<ExcelLineData> wExcelLineDataList,
                                                 OutResult<Integer> wErrorCode) {
        WMSArrivalNoticeItemImpo wResult = new WMSArrivalNoticeItemImpo();
        try {
            //仓库号
            wResult.StoreCode = wExcelLineDataList.get(3).colData.get(3);
            //仓库名称
            wResult.StoreName = wExcelLineDataList.get(3).colData.get(8);
            //项目名称
            wResult.ProjectName = wExcelLineDataList.get(4).colData.get(8);
        } catch (Exception ex) {
            logger.error("GetHeadInfo", ex);
        }
        return wResult;
    }

    //region 自动创建WMS单据
    // 1 创建到货通知单，通过Excel导入明细，
    // 2 根据到货通知单，创建收货单 进行物料交接；
    // 3 根据收货单创建入库单，将物料分到不同库位上；


    //endregion

}
